package cn.xn.hrms.api.controller;

import cn.xn.hrms.api.dto.res.RecruitmentDTO;
import cn.xn.hrms.domain.service.RecruitmentService;
import cn.xn.hrms.domain.utils.ResultVo;
import cn.xn.hrms.api.dto.req.RecruitmentReqDTO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Set;

/**
 * @author ysz
 */
@RestController
public class RecruitmentController {
    @Resource
    RecruitmentService recruitmentService;

    /**
     * 分页查询招聘列表
     *
     * @param page
     * @param size
     * @param departmentId
     * @param recruitStatus
     * @return
     */
    @GetMapping("/recruit/list")
    @ApiOperation("分页查询招聘列表")
    public PageInfo<RecruitmentDTO> list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                         @RequestParam(value = "size", defaultValue = "10") Integer size,
                                         @RequestParam(value = "departmentId", required = false) Integer departmentId,
                                         @RequestParam(value = "recruitStatus", defaultValue = "0") Integer recruitStatus) {
        return recruitmentService.findAll(departmentId, recruitStatus, page, size);
    }

    /**
     * 招聘列表
     *
     * @return
     */
    @GetMapping("/recruit/all")
    @ApiOperation("招聘列表")
    public List<RecruitmentDTO> list() {
        return recruitmentService.all();
    }

    /**
     * 新增招聘
     *
     * @param recruitmentReqDTO
     * @return
     */
    @PostMapping("/recruit")
    @ApiOperation("新增招聘")
    public ResultVo insert(@RequestBody @Valid RecruitmentReqDTO recruitmentReqDTO) {
        recruitmentService.insert(recruitmentReqDTO);
        return ResultVo.success();
    }

    /**
     * 修改招聘
     *
     * @param recruitmentReqDTO
     * @param id
     * @return
     */
    @PutMapping("/recruit/{id}")
    @ApiOperation("修改招聘")
    public ResultVo update(@RequestBody RecruitmentReqDTO recruitmentReqDTO, @PathVariable Integer id) {
        recruitmentService.updateById(id, recruitmentReqDTO);
        return ResultVo.success();
    }

    /**
     * 删除招聘（支持批量）
     *
     * @param id
     * @return
     */
    @DeleteMapping("/recruit/delete")
    @ApiOperation("删除招聘（支持批量）")
    public ResultVo deleteIdIn(@RequestBody Set<Integer> id) {
        recruitmentService.deleteByIdIn(id);
        return ResultVo.success();
    }
}
